package com.ssy.lingxi.platform.manage.controller.content;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.content.MemberCategory;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberCategoryRequest;
import com.ssy.lingxi.platform.manage.model.response.MemberCategoryResponse;
import com.ssy.lingxi.platform.manage.service.content.IMemberCategoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @menu 内容能力-分类管理
 * @author wyx
 * @version 2.0.0
 * @date 2021-09-28
 */
@RestController
@RequestMapping("/manage/member/category")
public class MemberCategoryController extends BaseController {

    @Resource
    private IMemberCategoryService memberCategoryService;


    /**
     * 所有分类
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping("/all")
    public Wrapper<List<MemberCategoryResponse>> all(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        if (memberId != null && roleId != null) {
            user.setMemberId(memberId);
            user.setMemberRoleId(roleId);
        } else {
            user = getSysUser();
        }
        return memberCategoryService.all(user);
    }

    /**
     * 分类详情
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/get")
    public Wrapper<MemberCategory> get(@Validated CommonIdRequest request) {
        return memberCategoryService.get(request);
    }

    /**
     * 新增
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({MemberCategoryRequest.Add.class}) MemberCategoryRequest request) {
        return memberCategoryService.add(request, getSysUser());
    }

    /**
     * 修改
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({MemberCategoryRequest.Update.class}) MemberCategoryRequest request) {
        return memberCategoryService.update(request, getSysUser());
    }

    /**
     * 删除
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return memberCategoryService.delete(request, getSysUser());
    }

    /**
     * 推荐分类
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping("/recommend")
    public Wrapper<List<MemberCategoryResponse>> recommend(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberCategoryService.recommend(user);
    }
}
